﻿; (function (window, undefined, $) {
    $(document).ready(function () {
        var gridopt = {
            url: options.listUrl,
            colModel: [

                  //  { display: '编号', name: 'ID', width: "3%", sortable: true, hide: false, align: 'left', iskey: true },

                 //   { display: '理财经理编号', name: 'UserID', width: "7%", hide: true, sortable: false, align: 'left' },
                 //   { display: '理财经理', name: 'UserName', width: "7%", sortable: false, align: 'left' },

                 //   { display: '团队经理编号', name: 'TeamUserID', width: "1%", hide: true, sortable: false, align: 'left' },
                 //   { display: '团队经理', name: 'TeamName', width: "7%", sortable: false, align: 'left' },		
                  //  { display: '团队总监编号', name: 'ChiefUserID', width: "1%", hide: true, sortable: false, align: 'left' },
                  //  { display: '团队总监', name: 'ChiefName', width: "7%", sortable: false, align: 'left' },

                 //   { display: '客户编号', name: 'MemberID', width: "7%", hide: true, sortable: false, align: 'left' },
                 //   { display: '客户名称', name: 'MemberName', width: "7%", sortable: false, align: 'left' },

                //    { display: '部门编号', name: 'DepartmentID', width: "7%", hide: true, sortable: false, align: 'left' },
                 //   { display: '部门名称', name: 'DeptName', width: "7%", sortable: false, align: 'left' },
                 //   { display: '客户电话', name: 'MobilePhone', width: "7%", sortable: false, align: 'left' },
                 //   { display: '客户来源', name: 'CustomerSource', width: "7%", sortable: false, align: 'left', process: formatCustomerSource },
                 //   { display: '联系日期', name: 'ContactDate', width: "7%", sortable: false, align: 'left' },
                 //   { display: '跟进方式', name: 'FollowUpMode', width: "7%", sortable: false, align: 'left', process: formatFollowUpMode },


                    { display: '编号', name: 'ID', width: "4%", sortable: true, hide: true, align: 'left', iskey: true },
                    { display: '理财经理', name: 'UserName', width: "6%", sortable: false, align: 'left' },
                    { display: '团队经理', name: 'TeamName', width: "6%", sortable: false, align: 'left' },
                    { display: '团队总监', name: 'ChiefName', width: "6%", sortable: false, align: 'left' },
                    { display: '部门名称', name: 'DeptName', width: "6%", sortable: false, align: 'left' },
                    { display: '客户姓名', name: 'RealName', width: "6%", sortable: false, align: 'left' },
                    { display: '客户电话', name: 'MobilePhone', width: "8%", sortable: false, align: 'left' },
                    { display: '客户来源', name: 'CustomerSource', width: "6%", sortable: false, align: 'left', process: formatCustomerSource },
                    { display: '联系日期', name: 'ContactDate', width: "6%", sortable: false, align: 'left' ,process: formatTime},
                    { display: '跟进方式', name: 'FollowUpMode', width: "6%", sortable: false, align: 'left', process: formatFollowUpMode },

                    { display: '跟进内容', name: 'FollowUpContent', width: "7%", sortable: false, align: 'left' },
                    { display: '跟进状态', name: 'FollowUpStatus', width: "7%", sortable: false, align: 'left', process: formatFollowUpStatus },
                    { display: '下次跟进日期', name: 'NextContactDate', width: "7%", sortable: false, align: 'left', process: formatTime },
                    { display: '客户状态', name: 'CustomerStatus', width: "7%", sortable: false, align: 'left', process: formatCustomerStatus },
                    { display: '销售失败原因', name: 'FailReason', width: "7%", sortable: false, align: 'left' },
                    { display: '操作', name: 'ID', width: "7%", sortable: false, align: 'center', process: processOp }

            ],
            sortname: "ID",
            sortorder: "ASC",
            title: false,
            rp: 15,
            usepager: true,
            showcheckbox: false
        };
        var xjgrid = new xjGrid("gridlist", gridopt);
        function processOp(value, cell) {
            var ops = [];
            ops.push("&nbsp;<a title='编辑' href='javascript:;'  onclick=\"util.Edit('", value, "')\"><i class='fa fa-edit' ></i>编辑</a>");
            //ops.push("&nbsp;&nbsp;<a title='删除' class='abtn' href='javascript:;'  onclick=\"util.Delete('", value, "','", cell[1], "')\"><i class='fa fa-trash-o' ></i>删除</a>");
            //ops.push("&nbsp;&nbsp;<a title=' 邮箱认证' class='abtn' href='javascript:;'  onclick=\"util.CertifiedMail('", value, "','", cell[1], "')\"><i class='fa fa-trash-o' >邮箱认证</i></a>");
            //ops.push("&nbsp;&nbsp;<a title=' 修改密码' class='abtn' href='javascript:;'  onclick=\"util.Auth('", value, "')\"><i class='fa fa-trash-o' ></i>修改密码</a>");

            return ops.join("");
        }
        function processInput(value, cell) {
            var ops = [];
            ops.push("<input id=\"Checkbox1\" type=\"checkbox\" value=\"", value, "\" />");
            //ops.push("&nbsp;&nbsp;<a title='删除' class='abtn' href='javascript:;'  onclick=\"util.Delete('", value, "','", cell[1], "')\"><i class='fa fa-trash-o' ></i>删除</a>");
            //ops.push("&nbsp;&nbsp;<a title=' 邮箱认证' class='abtn' href='javascript:;'  onclick=\"util.CertifiedMail('", value, "','", cell[1], "')\"><i class='fa fa-trash-o' >邮箱认证</i></a>");
            //ops.push("&nbsp;&nbsp;<a title=' 修改密码' class='abtn' href='javascript:;'  onclick=\"util.Auth('", value, "')\"><i class='fa fa-trash-o' ></i>修改密码</a>");

            return ops.join("");
        }//客户来源
        function formatCustomerSource(value, cell) {
            if (value == 1) {
                return '引入-派单';
            }
            else if (value == 2) {
                return '电话-引入';
            }
        }//跟进方式
        function formatFollowUpMode(value, cell) {
            if (value == 1) {
                return '接待面谈一';
            }
            else if (value == 2) {
                return '接待面谈二';
            }
        }//跟进状态
        function formatFollowUpStatus(value, cell) {
            if (value == 1) {
                return '参加公司宣讲等活动一';
            }
            else if (value == 2) {
                return '参加公司宣讲等活动二';
            }
        }//客户状态
        function formatCustomerStatus(value, cell) {
            if (value == 1) {
                return '意向客户一';
            }
            else if (value == 2) {
                return '意向客户二';
            }
        }
        function formatIDType(value, cell) {//证件类型
            if (value == 1) {
                return '身份证';
            }
            else if (value == 2) {
                return '护照';
            }
            else if (value == 3) {
                return '军官证';
            }
            else if (value == 4) {
                return '表示港澳台居民来往大陆通行证';
            }
        }
        function formatEducation(value, cell) {
            if (value == 1) {
                return '高中';
            }
            else if (value == 2) {
                return '本科';
            } else if (value == 3) {
                return '硕士';
            } else if (value == 4) {
                return '博士';
            }
        }

        //修改时间在控件中的显示长度，只显示日期
        function formatTime(value, cell) {
            var array = value.split("/");
            return array[0] +"/"+ array[1] +"/"+ array[2].substring(0,2);
        }

        $("#formQuery").submit(function () {
            xjgrid.Query(this);
            return false;
        });
        $("#btnSearch").click(function () {
            $("#formQuery").submit();
        });
        $("#btnAdd").click(function (e) {
            var url = options.editUrl;
            location.href = url;
        });
        //$("#btnAssign").click(function (e) {
        //    var url = options.assignUrl;
        //    location.href = url;
        //});
        $("#btnAssign").click(function (e) {
            $.layer({
                type: 2,
                shade: [0.5, '#000'],
                fix: true,
                title: '编辑用户',
                maxmin: false,
                iframe: { src: options.assignUrl },
                area: ['800px', '440px'],
                end: function (index) {
                    //var sss = document.getElementById("id").value;
                    xjgrid.Reload();
                }
            });
        });

        util.Edit = function (id) {
            //var url = options.editUrl + "/" + id;
            var url = options.editUrl + "/" + id;

            location.href = url;
        };
        util.CertifiedMail = function (id, name) {
            $.layer({
                type: 2,
                shade: [0],
                fix: false,
                title: '邮箱认证',
                maxmin: false,
                iframe: { src: options.CertifiedmailUrl + "?name=" + name },
                area: ['660px', '400px'],
                close: function (index) {
                    //子窗口返回值 layer.getChildFrame('#name', index).val()
                    //layer.msg('您获得了子窗口标记：' + layer.getChildFrame('#name', index).val(), 3, 1);
                },
                end: function (index) {
                    //$('#lbEnterpriseName').html($('#hideEName').val());
                }
            });
        };
        util.Auth = function (id) {
            $.layer({
                type: 2,
                shade: [0],
                fix: false,
                title: '会员密码',
                maxmin: false,
                iframe: { src: options.AuthenticateUrl + "/" + id },
                area: ['660px', '400px'],
                close: function (index) {
                    //子窗口返回值 layer.getChildFrame('#name', index).val()
                    //layer.msg('您获得了子窗口标记：' + layer.getChildFrame('#name', index).val(), 3, 1);
                },
                end: function (index) {
                    //$('#lbEnterpriseName').html($('#hideEName').val());
                }
            });
        };
        util.Delete = function (id, name) {
            if (!confirm("您确定要执行删除操作吗？")) {
                return false;
            }
            $.post(options.deleteUrl + "/" + id, { id: id },
                  function (res) {
                      if (res.Status > 0) {
                          alert("操作成功！");

                          xjgrid.Reload();
                      }
                      else {
                          alert("操作失败！");
                      }
                  },
                  "json"
            );
        };
    });

})(window, undefined, jQuery);